#include <Arduino.h>

// put function declarations here:
int in1_pin = 2;
int in2_pin = 3;
int in3_pin = 4;
int in4_pin = 5;
int speed1_pin = 6;
int speed2_pin = 9;

void setup()
{
  // put your setup code here, to run once:
  pinMode(in1_pin, OUTPUT);
  pinMode(in2_pin, OUTPUT);
  pinMode(in3_pin, OUTPUT);
  pinMode(in4_pin, OUTPUT);
  pinMode(speed1_pin, OUTPUT);
  pinMode(speed2_pin, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  // 正转
  for (int i = 0; i <= 255; i++)
  {
    analogWrite(speed1_pin, i);
    digitalWrite(in1_pin, LOW);
    digitalWrite(in2_pin, HIGH);
    delay(10);
  }
  for (int i = 255; i >= 0; i--)
  {
    analogWrite(speed1_pin, i);
    digitalWrite(in1_pin, LOW);
    digitalWrite(in2_pin, HIGH);
    delay(10);
  }
  delay(1000);
  // 反转
  for (int i = 0; i <= 255; i++)
  {
    analogWrite(speed1_pin, i);
    digitalWrite(in1_pin, HIGH);
    digitalWrite(in2_pin, LOW);
    delay(10);
  }
  for (int i = 255; i >= 0; i--)
  {
    analogWrite(speed1_pin, i);
    digitalWrite(in1_pin, HIGH);
    digitalWrite(in2_pin, LOW);
    delay(10);
  }
  delay(1000);
}

// put function definitions here: